import time
from selenium import webdriver


class Kaishiba():
    def __init__(self):
        self.url = "https://www.kaishiba.com/project/more"
        self.driver = webdriver.Chrome()

    def get_content_list(self):
        content_list = []
        li_list = self.driver.find_elements_by_xpath('//ul[@class="screen-list moreli"]/li')
        for li in li_list:
            item = {}
            item["title"] = li.find_element_by_xpath('.//div[@class="cardBox"]/a[@class="title"]').text
            item["author"] = li.find_element_by_xpath('.//div[@class="detail"]/div/span').text
            print(item)
            content_list.append(item)
        return content_list

    def save_content_list(self, content_list):
        pass

    def run(self):
        self.driver.get(self.url)
        while True:
            js = "window.scrollTo(0,document.body.scrollHeight)"
            self.driver.execute_script(js)
            time.sleep(10)
            content_list = self.get_content_list()
            self.save_content_list(content_list)
            if len(content_list) == 1800:
                break


if __name__ == "__main__":
    go = Kaishiba()
    go.run()
